using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class RefundMap : EntityTypeConfiguration<Refund>
    {
        public RefundMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.REFUND_ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.REFERENCE)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.ID)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.DESC)
                .HasMaxLength(40);

            this.Property(t => t.ENTITY)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.INVNO)
                .HasMaxLength(8);

            this.Property(t => t.CASHACCT)
                .HasMaxLength(40);

            this.Property(t => t.TYPE)
                .HasMaxLength(2);

            this.Property(t => t.BATCH)
                .HasMaxLength(8);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Refunds");
            this.Property(t => t.REFUND_ID).HasColumnName("REFUND_ID");
            this.Property(t => t.REFERENCE).HasColumnName("REFERENCE");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.CASHAMT).HasColumnName("CASHAMT");
            this.Property(t => t.AMT).HasColumnName("AMT");
            this.Property(t => t.AMTDOL).HasColumnName("AMTDOL");
            this.Property(t => t.AMTACCT).HasColumnName("AMTACCT");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.ENTITY).HasColumnName("ENTITY");
            this.Property(t => t.INVNO).HasColumnName("INVNO");
            this.Property(t => t.CASHACCT).HasColumnName("CASHACCT");
            this.Property(t => t.CASHCURR).HasColumnName("CASHCURR");
            this.Property(t => t.CUSTCUR).HasColumnName("CUSTCUR");
            this.Property(t => t.PAYERTYPE).HasColumnName("PAYERTYPE");
            this.Property(t => t.TYPE).HasColumnName("TYPE");
            this.Property(t => t.POSTED).HasColumnName("POSTED");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.PsPayment_id).HasColumnName("PsPayment_id");

            // Relationships
            this.HasOptional(t => t.Acct)
                .WithMany(t => t.Refunds)
                .HasForeignKey(d => d.CASHACCT);
            this.HasOptional(t => t.Cstctr)
                .WithMany(t => t.Refunds)
                .HasForeignKey(d => d.CSTCTRID);
            this.HasRequired(t => t.Cust)
                .WithOptional(t => t.Refund);
            this.HasOptional(t => t.PSPayment)
                .WithMany(t => t.Refunds)
                .HasForeignKey(d => d.PsPayment_id);

        }
    }
}
